package com.glsc.ngateway.common.api.oaflow.resp;

import lombok.Data;
import lombok.ToString;
import org.apache.logging.log4j.util.Strings;

@Data
@ToString
public class OaflowResponse<T> {

    public static final String Success = "0";
    public static final String Fail = "-1";

    //getWorkFlowInfos
    public static final String requestId = "requestId";
    public static final String requestName = "requestName";
    public static final String flowStatusType = "flowStatusType";
    public static final String flowNode = "flowNode";
    public static final String flowNodeCode = "flowNodeCode";
    public static final String workFlowName = "workflowName";
    public static final String workFlowId = "workFlowId";
    public static final String workFlowTypeName = "workFlowTypeName";

    //申请人
    public static final String applicant = "applicant";
    //申请部门
    public static final String applicantDepart = "applicantDepart";
    //
    public static final String applicantComp = "applicantComp";


    public static final String flowInfos = "flowInfos";

    //getWorkFlowStatus
    public static final String requestStatus = "requestStatus";
    public static final String requestlogType = "logType";

    //getSenderFilesDetailByName反馈
    public static final String isReturn = "isReturn";
    public static final String groupId = "groupId";


    public String getCode() {
        return code;
    }

    public String getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    String code;
    String status;
    String msg;
    T data;


    public static <T> OaflowResponse<T> successData(T data) {
        OaflowResponse<T> response = new OaflowResponse<>();
        response.setCode(Success);
        response.setStatus("SUCCESS");
        response.setData(data);
        return response;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static OaflowResponse<Void> success() {
        return successMsg(null);
    }
    public static OaflowResponse<Void> successMsg(String msg) {
        OaflowResponse<Void> response = new OaflowResponse<>();
        response.setCode(Success);
        response.setStatus(Strings.isBlank(msg) ? "SUCCESS": msg);
        response.setMsg(Strings.isBlank(msg) ? "SUCCESS": msg);
        return response;
    }
    public static OaflowResponse<Void> failMsg(String errMsg) {
        OaflowResponse<Void> response = new OaflowResponse<>();
        response.setCode(Fail);
        response.setStatus(errMsg);
        response.setMsg(errMsg);
        return response;
    }

    public static <T> OaflowResponse<T> failData(T data) {
        OaflowResponse<T> response = new OaflowResponse<>();
        response.setCode(Fail);
        response.setStatus("FAIL");
        response.setData(data);
        return response;
    }

    public boolean isSuccess(){
        return this.getCode().equals(Success);
    }

    public boolean isFailed(){
        return this.getCode().equals(Fail);
    }
}
